import applyAPI from "../api/applyAPI";

export {hsTypes, hsModule, hsActionTypes, ZY_HS_ID}

const hsTypes = {
  SAVE_HS_ID: 'HS_SAVE_HS_ID',
  SAVE_HS_CONFIG: 'SAVE_HS_CONFIG',
  SAVE_PLAN_ID: 'SAVE_PLAN_ID',
  SAVE_HS_INFO: "SAVE_HS_INFO",
};

/**
 *  44 默认知业tsId
 *  46 顺邦
 *  42 好房通
 *
 * */

const ZY_HS_ID = 50;
const hsActionTypes = {
  GET_HS_INFO: "GET_HS_INFO"
};

const hsModule = {
  //保存在全局的模块数据
  state: {
    hsId: ZY_HS_ID,
    hsConfig: undefined,
    hsLocalConfig: {
      // '242': {},
      // '14': {
      //   'apiPath': 'ganzhou',
      // },
      // '9': {
      //   'apiPath': 'kunming',
      // },
      // '37': {
      //   'apiPath': 'guiyang',
      // },
    },
    hsInfo: undefined,
    planId: ''
  },
  //获取数据
  getters: {
    hsApiPath: (state) => {
      let localConfig = state.hsLocalConfig[state.hsId] || {};
      return localConfig['apiPath']
    },
    hsId: (state) => state.hsId || ZY_HS_ID,
    hsConfig: (state) => state.hsConfig || {},
    hsLogoM: (state, getters) => getters.hsConfig["logoM"],
    getPlanId: (state, getters) => state.planId,
    hsInfo: (state) => state.hsInfo,
  },
  //同步请求，只有这里能修改数据
  mutations: {
    [hsTypes.SAVE_HS_ID](state, hsId) {
      if (hsId) {
        state.hsId = hsId
      }
    },
    [hsTypes.SAVE_HS_CONFIG](state, hsConfig) {
      if (hsConfig) {
        state.hsConfig = hsConfig
      }
    },
    [hsTypes.SAVE_PLAN_ID](state, id) {
      if (id) {
        state.planId = id
      }
    },
    [hsTypes.SAVE_HS_INFO](state, data) {
      if (data) {
        state.hsInfo = data
      }
    }

  },
  //异步请求
  actions: {
    [hsActionTypes.GET_HS_INFO]({state, commit}, data) {
      applyAPI.getTSInfoById(state.hsId)
        .then(result => {
          commit(hsTypes.SAVE_HS_INFO, result.responseData)
        })

    },
  },
}


